package com.yunfei.api.v1.magerIndcInfo;

import com.yunfei.api.v1.directionary.contants.CardTypeContant;
import com.yunfei.api.v1.directionary.result.CardTypeResultBo;
import com.yunfei.api.v1.magerIndcInfo.contants.MagerIndcInfoContant;
import com.yunfei.api.v1.magerIndcInfo.param.CaCustIdParam;
import com.yunfei.api.v1.magerIndcInfo.param.CrmMagerIdParam;
import com.yunfei.api.v1.magerIndcInfo.param.MagerIndcInfoParam;
import com.yunfei.api.v1.magerIndcInfo.param.TemplateManagerParam;
import com.yunfei.api.v1.magerIndcInfo.result.FaRenInfoResult;
import com.yunfei.api.v1.magerIndcInfo.service.MagerIndcInfoService;
import com.yunfei.bo.result.ResultModel;
import com.yunfei.enums.ResultStatus;
import com.yunfei.fegin.RedisFeignService;
import com.yunfei.mapper.aiiidb.GetStatusMapper;
import com.yunfei.mapper.aiiidb.MagerIndcInfoMapper;
import com.yunfei.mapper.aiiidb.MagerIndcInfoTemplateMapper;
import com.yunfei.mapper.aiiidb.TPersonalUserMapper;
import com.yunfei.ribbon.RedisServiceRibbon;
import com.yunfei.service.RedisService;
import com.yunfei.service.ValidMobileAndCodeService;
import com.yunfei.yunhetong.magerIndeInfo.entity.MagerIndcInfoEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 管理人信息
 * @Author: zhengyunfei
 * @Date: 2018/6/15
 * @time:11:26
 */
@SuppressWarnings("ALL")
@RestController
@RequestMapping("/api/v1/magerIndcInfo")
@Api(value = CardTypeContant.NAMESPACE,tags =  CardTypeContant.NAMESPACE )
public class MagerIndcInfoApiController {
    @Autowired
    private TPersonalUserMapper tPersonalUserMapper;
    @Autowired
    private GetStatusMapper getStatusMapper;
    @Autowired
    private RedisFeignService redisFeignService;
    @Autowired
    private RedisService redisService;
    @Autowired
    private RedisServiceRibbon redisServiceRibbon;
    @Autowired
    private ValidMobileAndCodeService validMobileAndCodeService;
    @Autowired
    private Environment env;
    @Autowired
    private MagerIndcInfoMapper magerIndcInfoMapper;
    @Autowired
    private MagerIndcInfoTemplateMapper magerIndcInfoTemplateMapper;
    @Autowired
    private MagerIndcInfoService magerIndcInfoService;
    /**
     * @Description: 管理人信息新增
     * @Author: zhengyunfei
     * @Date: 2019/7/29
     * @time:10:30
     */
    @PostMapping(value="/add")
    @ApiOperation(value = MagerIndcInfoContant.ADD,notes = MagerIndcInfoContant.ADD,position = 1,response = ResultModel.class)
    @ResponseBody
    public Object add(MagerIndcInfoParam param){
        ResultModel resultModel=new ResultModel();
        Map<String,Object> queryMap=new HashMap<>();
        try{
            MagerIndcInfoEntity magerIndcInfoEntity=new MagerIndcInfoEntity();
            String caCustId=param.getCaCustId();
            if(caCustId.contains("\"")){
                caCustId=caCustId.replace("\"","");
            }
            magerIndcInfoEntity.setCustNm(param.getCustNm());
            magerIndcInfoEntity.setCertTyp(param.getCertTyp());
            magerIndcInfoEntity.setCertNo(param.getCertNo());
            magerIndcInfoEntity.setMobileNo(param.getMobileNo());
            magerIndcInfoEntity.setIdenCardTyp("B2");
            magerIndcInfoEntity.setCrmMagerId(param.getCrmMagerId());
            magerIndcInfoEntity.setCaCustId(caCustId);
            magerIndcInfoEntity.setIdenUser(param.getIdenUser());
            magerIndcInfoMapper.add(magerIndcInfoEntity);
            resultModel.setCode(ResultStatus.SUCCESS.getCode());
            resultModel.setMessage(ResultStatus.SUCCESS.getMessage());
        }catch (Exception e){
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
            e.printStackTrace();
        }
        return resultModel;
    }
    /**
     * @Description: 合同模板添加和删除
     * @Author: zhengyunfei
     * @Date: 2019/7/29
     * @time:10:30
     */
    @PostMapping(value="/template/save")
    @ApiOperation(value = MagerIndcInfoContant.ADD,notes = MagerIndcInfoContant.ADD,position = 1,response = ResultModel.class)
    @ResponseBody
    public Object templateAdd(TemplateManagerParam param){
        ResultModel resultModel=new ResultModel();
        Map<String,Object> queryMap=new HashMap<>();
        try{
            magerIndcInfoService.add(param);
            resultModel.setCode(ResultStatus.SUCCESS.getCode());
            resultModel.setMessage(ResultStatus.SUCCESS.getMessage());
        }catch (Exception e){
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
            e.printStackTrace();
        }
        return resultModel;
    }
    /**
    * @Description: 编辑页面初始化
    * @Author: zhengyunfei
    * @Date: 2019/8/19
    * @time:14:20
    */
    @PostMapping(value="/edite")
    @ApiOperation(value = MagerIndcInfoContant.EDITE,notes = MagerIndcInfoContant.EDITE,position = 1,response = ResultModel.class)
    @ResponseBody
    public Object getFaRenInfo(CaCustIdParam param, CrmMagerIdParam crmMagerIdParam){
        ResultModel resultModel=new ResultModel();
        Map<String,Object> resultMap=new HashMap<>();
        try{
            String caCustId=param.getCaCustId();
            String crmMagerId=crmMagerIdParam.getCrmMagerId();
            Map<String,Object> queryMap=new HashMap<>();
            queryMap.put("caCustId",caCustId);
            queryMap.put("crmMagerId",crmMagerId);
            FaRenInfoResult faRenInfoResult=magerIndcInfoService.getFaRenInfo(queryMap);
            resultMap.put("info",faRenInfoResult);
            List<CardTypeResultBo> cardTypeResultBo=magerIndcInfoService.getCardType(queryMap);
            resultMap.put("cardTypeList",cardTypeResultBo);
            resultModel.setCode(ResultStatus.SUCCESS.getCode());
            resultModel.setMessage(ResultStatus.SUCCESS.getMessage());
            resultModel.setData(resultMap);
        }catch (Exception e){
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
            e.printStackTrace();
        }
        return resultModel;
    }

}
